Repository navigation
Log a telemetry event for each databricks skills command run - #8145
simonfaltum wants to merge 3 commits into
Conversation
Each run of list, read, list-files, read-file or search logs one SkillsCommandEvent: the command, the skill name for a successful read of a published skill, the catalog release version, the source that served it, the outcome and an error category. The calling agent is recorded in the execution context, as the aitools events do. Events follow the existing telemetry opt-out and are uploaded in the background, best effort. The skills commands exist only when DATABRICKS_SKILLS_PREVIEW is set, so nothing changes with it unset. Co-authored-by: Isaac <no-reply@databricks.com>
Regression test report ✅Commit: Selected 1 changed tests (limit=20, 0 not selected) 1 tests: regression=1 unreleased=0 coverage=0 failing=0
TestAccept/cmd/skills/telemetry: branch ✅ | main (905b0f7) ❌ | latest (v1.28.0) ❌main (905b0f7): latest (v1.28.0): |
✅ Integration test reportCommit: a9c450c
Top 6 slowest tests (at least 2 minutes):
|
A read-file reads the catalog once, after the read succeeds, for the release version and to check that the skill is listed. A failed read makes no catalog call. With telemetry off, the commands install no record, so they make no extra call. Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
Automated review at 33bbebb. Each finding was verified against the code.
Not ready yet: 1 open question(s) about a change users could be hurt by.
This PR makes each databricks skills command log a SkillsCommandEvent. It records what the folder source read and reports the calling agent in the execution context. The wiring looks right: the wrapper order, the opt-out and the catalog reads all hold up. There are some gaps, though. An oversized manifest isn't classified the way its doc says. The "published" check reads env vars that the package doc says only ref.go/fetch.go read. Two acceptance cases can't fail for the reason their titles give. The remaining open question is the unconditional auth wait on every run.
Questions
- [blocking]
recordRunssetsWaitAtExit = truewhen each skills command is registered. Every run logs an event, so every run waits up totelemetryAuthBudgetfor auth, including cheap failures likeskills search " "or a run that ends withErrNoSource. TheTelemetryAuth.WaitAtExitdoc says it is false by default and is set only once a run is worth the wait, andinstall/instrumentCommandfollow that. Should the wait be set only afterResolve/Catalogsucceed? If you keep it on every run, the comment's "as install does" should be changed, since install only waits after plan confirmation.
| return protos.SkillsErrorCategoryFileNotFound | ||
| case errors.Is(err, libskills.ErrNoSource), errors.Is(err, libskills.ErrSourceUnreachable): | ||
| return protos.SkillsErrorCategorySourceUnavailable | ||
| case errors.Is(err, libskills.ErrUnsafeManifestPath), syntax, typed: |
There was a problem hiding this comment.
[nice to have] The doc on ErrManifestTooLarge in libs/skills/fetch.go says the command layer classifies it like a manifest that does not parse. fsSource.manifest returns it unwrapped, but this switch only checks ErrUnsafeManifestPath and the JSON errors, so a manifest over MaxFetchBodySize is reported as UNCATEGORIZED. Can you add errors.Is(err, libskills.ErrManifestTooLarge) to this case, plus a row for it in TestErrorCategory?
There was a problem hiding this comment.
Fixed in a9c450c: errorCategory now maps ErrManifestTooLarge to CATALOG_INVALID, and TestErrorCategory has a row for it.
| // namesArePublished reports whether this source's skill names are published ones. A folder's names, and those of a ref | ||
| // or base URL the user chose, are the user's own. | ||
| func (r *recordingSource) namesArePublished(ctx context.Context) bool { | ||
| return r.rec.Origin != OriginFolder && env.Get(ctx, "DATABRICKS_SKILLS_REF") == "" && env.Get(ctx, "DATABRICKS_SKILLS_BASE_URL") == "" |
There was a problem hiding this comment.
[nice to have] namesArePublished reads DATABRICKS_SKILLS_REF and DATABRICKS_SKILLS_BASE_URL directly. The package doc in skills.go says ref.go and fetch.go are the only code here that reads them. With the only wired origin (OriginFolder), the first condition already returns false, so these checks never run today. Could Resolve pass a published bool to record(...), decided where the ref and base URL are actually resolved? You could also add the checks together with the live source, so that the two can't drift apart.
There was a problem hiding this comment.
Not in this PR. This branch has no live source yet, and the code that reads DATABRICKS_SKILLS_REF and DATABRICKS_SKILLS_BASE_URL arrives with it, so the folder origin never reaches this check today. Until then the check stays on the recording path, where TestRecordSkillName covers the ref and base URL cases. When the live source lands, it can decide published where it picks its ref and pass the flag to record, so the two cannot drift. Tracked as a follow-up.
| trace print_skills | ||
|
|
||
| title "with telemetry disabled, no event is recorded" | ||
| DATABRICKS_CLI_DISABLE_TELEMETRY=1 trace $CLI skills read guide-skill > /dev/null |
There was a problem hiding this comment.
[nice to have] telemetry.Upload already returns early on DATABRICKS_CLI_DISABLE_TELEMETRY, so this golden would stay empty even if recordRuns still installed the record and logged the event. The case doesn't cover the early return in recordRuns. In the same way, the "a failed read sends no name" case (line 26) reads from a folder, which never sends a name, so it would pass even if a failed read sent the name. Could you add a unit test that checks telemetry.BufferedEvents after a run with telemetry disabled, and retitle the two cases to say what they show (nothing uploaded; the error category and the version)?
There was a problem hiding this comment.
Done in a9c450c. The two cases are retitled to what they show: nothing is uploaded with telemetry disabled, and a failed read sends the error category and the version. The rule that a failed read sends no name is covered by TestSkillsEventFailedReadSendsNoName, which runs the error path directly. TestRecordRunsDisabledLogsNothing checks BufferedEvents with telemetry disabled, so it fails if the wrapper logs.
|
|
||
| title "skills list under a coding agent: the event and the calling agent are uploaded" | ||
| export CLAUDECODE=1 | ||
| trace $CLI skills list > /dev/null |
There was a problem hiding this comment.
[nit] .agents/rules/testing.md asks for noisy output to go to LOG.<name>, not /dev/null. This line and lines 23 and 31 throw the command output away. Can these redirect to LOG.list / LOG.read like the LOG.on/LOG.off at the end?
There was a problem hiding this comment.
Done in a9c450c. The three runs that discarded output now write to LOG.list, LOG.read and LOG.disabled, as LOG.on and LOG.off do. The golden is unchanged.
| // logEvent buffers the event of a run for the upload at exit, and sets the calling agent for its execution context. | ||
| func logEvent(cmd *cobra.Command, command protos.SkillsCommand, rec *libskills.Record, err error) { | ||
| ctx := cmd.Context() | ||
| if telemetry.Disabled(ctx) { |
There was a problem hiding this comment.
[nit] logEvent is only called from the recordRuns wrapper, which has already returned early when telemetry.Disabled(cmd.Context()) is true, so this check can never fire. Can we drop it and keep the single check in recordRuns?
There was a problem hiding this comment.
Done in a9c450c. The check is removed from logEvent. recordRuns is its only caller and returns early when telemetry is disabled, and TestRecordRunsDisabledLogsNothing covers that path.
Classify an oversized manifest as a catalog error, drop the telemetry check in logEvent that recordRuns already makes, and add a test that a run with telemetry disabled logs nothing. The acceptance cases now send their output to LOG files, and the two cases that the folder source could not prove are retitled to what they show. Co-authored-by: Isaac <no-reply@databricks.com>
Changes
Each run of
databricks skills(list, read, list-files, read-file, search) logs oneSkillsCommandEvent: the command, the skill name for a successful read of a published skill, the catalog release version, the source that served it, the outcome, and an error category. The calling agent goes inExecutionContext.calling_agent, whichcmd/rootfills from the value thatcmd/skillsrecords for the run.libs/skillswraps the source thatResolvereturns, and records what was read when the command's context carries a record. A successful read reads the catalog once, for the version and the listing; a failed read makes no catalog call.cmd/skillswraps each command'sRunEonce, so the command files are unchanged.installdoes, and never fails or prompts the command.DATABRICKS_SKILLS_PREVIEWis set. With it unset, no path changes, and the new execution context field is omitted.Why
Without an event, nothing shows which skills agents load, from where, or through which agent. The event mirrors the
SkillsCommandEventmessage of the CLI log schema.Decisions to review
cmd/skillsimportscmd/aitools. The auth helper and the calling-agent lookup live there. ExportingWithTelemetryAuthandCallingAgentTypereuses them instead of copying them. Moving them tocmd/rootwould be cleaner and can follow as a separate refactor.skill_nameonly after a successful read of a listed skill, and never from a folder or a non-default ref or base URL. A failed read may carry a typo or private text.Resolvereturns theDATABRICKS_SKILLS_DIRfolder, so a run without it fails withSOURCE_UNAVAILABLE.LIVE,CACHEandBUNDLEDare defined for the sources that follow, and the published-name rule is covered by unit tests rather than acceptance.Tests
go test ./libs/skills/ ./cmd/skills/passes.TestRecordSkillNamecovers the name rules,TestRecordFolderSendsNoNamethe folder rule,TestRecordReadFileCatalogCallsthe catalog reads of a successful and a failed read, andTestErrorCategorythe categories.go test ./acceptance -run TestAccept/cmd/skillsand-run TestAccept/cmd/aitoolspass. The newcmd/skills/telemetrycase shows the uploaded payloads for list, read and a failed read, the calling agent, nothing uploaded with telemetry disabled, andTestRecordRunsDisabledLogsNothingchecks that no event is buffered, and identical output with telemetry on and off../task fmt-q lint-qandtools/check_deadcode.pyare clean.Not tested: the live release source, which this change does not add, and uploads to a real workspace.
This pull request and its description were written by Isaac.